#include <Arduino.h>
#include "main.h"
#include "Ticker.h"
#include "driver/adc.h"
#include "esp_adc_cal.h"
#include "power.h"
#include "mlx90640.h"
extern "C"
{
#include "LCD.h"
#include "GUI.h"
// #include "PIC.h"
#include "OneButton.h"
}

Ticker timer1;
OneButton powerButton(POWER_S, true);

void setup()
{
    Serial.begin(115200);
    while (!Serial)
        ;

    powerInit();
    LCD_Init();
    logo();
    checkPowerOn();
    timer1.attach_ms(100, timer1Callback);
    powerButton.attachLongPressStart(longPress);

    mlxInit();

    Serial.println("Setup done");
}

void loop()
{
    char bf[100];
    float voltage = readBatVoltage();
    Serial.printf("battery voltage: %f\r\n", voltage);

    sprintf(bf, "%f", voltage); 
    // mlxTest();
    mlxRefresh();
    // Gui_Drawbmp16(0, 0, 160, 128, gImage_pic);
    // Show_Str(10, 30, WHITE, WHITE, (const uint8_t *)bf, 12, 1);
    delay(100);
   

}

void logo()
{
    // Gui_Drawbmp16(0, 0, 160, 128, gImage_pic);
}
void longPress()
{
    Serial.println("longPress");
    powerOff();
}

void timer1Callback(){
     powerButton.tick();
}
